package com.training.java.core.collections.car.post15;

import java.util.LinkedHashSet;
import java.util.Set;

import com.training.java.core.collections.car.pre15.Car;

/**
 * The Main purpose this demo is to observe how LinkedHashSet is displaying the
 * values. Should not take duplicates. Should not take null. maintains the
 * objects in the Order how the user has added.
 * 
 * 
 * @author Satya
 * 
 */
public class CarLinkedHashSetDemo {

	public static void main(String[] args) {

		Car car1 = new Car("5334", "BMW", "X5");
		Car car2 = new Car("2345", "Ford", "Focus");
		Car car3 = new Car("3456", "Honda", "City");
		Car car4 = new Car("3456", "Honda", "City");// duplicate object with
													// different object
													// Reference
		Car car5 = new Car();

		// Creating HashSet to add multiple objects
		Set<Car> listOfCars = new LinkedHashSet<Car>();

		// Add Car Objects to the HashSet
		listOfCars.add(car1);
		listOfCars.add(car2);
		listOfCars.add(car3);
		listOfCars.add(car4);// same object with object reference
		listOfCars.add(car1);// Trying to add duplicate object with
		// listOfCars.add(car5);

		listOfCars.add(null); // trying to add null values

		// for each loop

		for (Car aCar : listOfCars)

		{

			// Print the VinNumber, Make, Model of the Cars
			System.out.println("VinNumber of the car : " + aCar.getVinNumber());
			System.out.println("Make of the car :  " + aCar.getMake());
			System.out.println("Model of the Car :" + aCar.getModel());
			System.out.println("***************************");

		}

	}

}
